<template>
    <!-- 对话框表单 -->
    <!-- 建议使用 Prettier 格式化代码 -->
    <!-- el-form 内可以混用 el-form-item、FormItem、ba-input 等输入组件 -->
    <el-dialog
        class="ba-operate-dialog"
        :close-on-click-modal="false"
        :model-value="['checkaction'].includes(baTable.form.operate!)"
        @close="baTable.toggleForm"
        width="700px"
    >
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                {{ checkForm.check_status === 2 ? t('支付') : t('驳回') }}
            </div>
        </template>
        <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
            <div class="show-info" :class="'ba-' + baTable.form.operate + '-form'">
                <div>
                    <div class="source-line">
                        <span class="source-title">相关资讯：</span>
                        <span class="source-desc">{{ baTable.table.extend!.infoData.name }}</span>
                    </div>
                    <div class="source-line">
                        <span class="source-title">金额：</span>
                        <span class="source-desc">{{ baTable.table.extend!.infoData.order_amount }}元</span>
                    </div>
                    <div class="source-line">
                        <span class="source-title">开户行：</span>
                        <span class="source-desc">{{ baTable.table.extend!.infoData.open_bank }}</span>
                    </div>
                    <div class="source-line">
                        <span class="source-title">收款人：</span>
                        <span class="source-desc">{{ baTable.table.extend!.infoData.truename }}</span>
                    </div>
                    <div class="source-line">
                        <span class="source-title">银行卡号：</span>
                        <span class="source-desc">{{ baTable.table.extend!.infoData.bankno }}</span>
                    </div>
                </div>
                <FormItem :label="t('转账截图')" v-if="baTable.table.extend!.infoData.check_status==2" type="image" v-model="checkForm.check_img" prop="check_img" />
                <FormItem  v-if="baTable.table.extend!.infoData.check_status==3"
                    :label="'驳回原因'"
                    :rows="4"
                    maxlength="200"
                    show-word-limit
                    type="textarea"
                    v-model="checkForm.check_msg"
                    prop="check_msg"
                    :placeholder="t('Please input field', { field: t('审核意见') })"
                />
            </div>
        </el-scrollbar>
        <template #footer>
            <div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
                <el-button @click="baTable.toggleForm()">{{ t('Cancel') }}</el-button>
                <el-button @click="confirmClick()" v-blur :loading="baTable.form.submitLoading" type="primary">
                    {{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') : t('提交') }}
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>
<script setup lang="ts">
import type { DrawerProps } from 'element-plus'
import { inject, reactive, ref } from 'vue'
const drawer = ref(true)
const direction = ref<DrawerProps['direction']>('rtl')
const radio1 = ref('Option 1')

import FormItem from '/@/components/formItem/index.vue'
import Check from './check.vue'
import {wicheckSumit} from '/@/api/backend/orders'
import { useConfig } from '/@/stores/config'
import type baTableClass from '/@/utils/baTable'
import { buildValidatorData } from '/@/utils/validate'
import { ElNotification } from 'element-plus'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
const config = useConfig()

const baTable = inject('baTable') as baTableClass
const handleClose = (done: () => void) => {}

const checkForm = reactive({
    check_mark: '',
    id: '',
    status: 3,
    check_status:'',
    check_img: '',
    check_msg: '',
    submitLoading: false,
})

function cancelClick() {}
function confirmClick() {
    baTable.form.submitLoading = true
    checkForm.id = baTable.table.extend!.infoData.id
    checkForm.check_status = baTable.table.extend!.infoData.check_status
    wicheckSumit(checkForm)
        .then((result) => {
            baTable.form.submitLoading = false
            checkForm.check_mark = ''
            checkForm.id = ''
            baTable.form.operate! = ''
            ElNotification({
                title: '',
                message: result.msg,
                type: 'success',
            })
            setTimeout(() => {
                baTable.getIndex()
            }, 2000)
        })
        .catch((err) => {
            baTable.form.submitLoading = false
        })
}
</script>
<style scoped>
.show-info {
    .el-row {
        margin-bottom: 20px;
    }
    .label-title {
        color: #b1b3b4;
    }
}
</style>
<style scoped>
:deep(.el-drawer__footer) {
    text-align: left;
    box-shadow: var(--el-box-shadow);
}
.source-title {
    font-size: 14px;
    font-weight: normal;
    line-height: 22px;
    letter-spacing: 0em;
    color: rgba(0, 0, 0, 0.4);
}
.source-desc {
    font-size: 14px;
    font-weight: normal;
    line-height: 22px;
    letter-spacing: 0em;
    color: rgba(0, 0, 0, 0.9);
}
.source-line {
    padding: 8px 0;
}
</style>
